const baseURL = 'https://api-hmugo-web.itheima.net/api/public/v1'
export const axios = function(params) {
// 发送拦截
    const token = wx.getStorageSync('token');
    if (/^\/my/.test(params.url)) {
        params.header = {
            Authorization : token 
        }
    }
   return new Promise ((resolve, reject)=>{
        if (!params.method) {
            params.method = "GET"
        }
        params.url = baseURL + params.url
        
        return wx.request({
            header: {'content-type':'application/json'},
            dataType: 'json',
            responseType: 'text',
            ...params,
            success: (result) => {
                resolve(result.data)
            },
            fail: (error) => {
                reject(error)
            },
            complete: () => {}
        });
    })   
}